package com.caigou.desensitization.strategy;

import com.caigou.desensitization.annotation.AutoClearDesensitization;

import com.caigou.desensitization.autoConfig.DesensitizationProperties;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Aspect
public class DesensitizationClearAspect {
	@Resource
	private DesensitizationProperties desensitizationProperties;

	@PostConstruct
	private void init() {
		boolean enabled =
				desensitizationProperties.isEnabled();
		if (!enabled) {
			System.out.println("已关闭功能!未开启字段脱敏功能");
		}
	}

	// 拦截带有 @DesensitizationControl 注解的方法
	@After("@annotation(desensitizationControl)")
	public void clearThreadLocal(AutoClearDesensitization desensitizationControl) {
		if (desensitizationProperties.isEnabled()) {
			DesensitizationContext.clear();
			System.out.println("已经清除DesensitizationContext");
		}
	}
}